package com.memo.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.memo.Eventbean.homeone_evetbean;
import com.memo.Eventbean.hometwo_eventbean;
import com.memo.R;
import com.memo.activity.EditActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class fragment_hometwo extends Fragment implements View.OnClickListener {
    FloatingActionButton hometwo;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        EventBus.getDefault().register(this);
        View view=inflater.inflate(R.layout.fragment_hometwo,container,false);
        hometwo=view.findViewById(R.id.hometwo_button);
        hometwo.setOnClickListener(this);
        return view;
    }

    public void setvisitly(boolean isvisit){
        if (isvisit){
            hometwo.setVisibility(View.VISIBLE);
        }else {
            hometwo.setVisibility(View.GONE);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onMessageEvent(hometwo_eventbean event) {
        if (event.getIssitivity()){
            setvisitly(true);
        }else {
            setvisitly(false);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.hometwo_button:
                getActivity().startActivity(new Intent(getActivity(), EditActivity.class));
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
